//
//  Tool.m
//  UI_lesson_12_2_UITableViewCellHeight
//
//  Created by lanou3g on 16/3/2.
//  Copyright © 2016年 Liu. All rights reserved.
//

#import "Tool.h"

@implementation Tool
//创建类方法计算 label 的高度
+ (CGFloat)labelHeightWithText:(NSString *)text font:(UIFont *)font
{
    CGSize size = CGSizeMake([[UIScreen mainScreen] bounds].size.width, MAXFLOAT);
    
    NSDictionary *dic = @{NSFontAttributeName:font};
    
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin
        attributes:dic context:nil];
    return rect.size.height;
}


//创建类方法根据 image 计算 imageView 的高度
+ (CGFloat)imageScaleHeightWith:(NSString *)imageName
{
    //创建一个 image
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]]];
    //给宽度
    CGFloat width = image.size.width;
    //给高度
    CGFloat height = image.size.height;
    
    
   
     return  height / width *[[UIScreen mainScreen] bounds].size.width;
}

+(CGFloat)imageScaleHeightWithImageUrl:(NSString *)imageurl width:(NSInteger)width height:(NSInteger)height
{
//     UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageurl]]];
   
    CGFloat imageWidth = [UIScreen mainScreen].bounds.size.width;
    
    CGFloat ImageHight = height * imageWidth /width ;
 
    if (width == 0 || height == 0) {
        ImageHight = 0;
    }
    return ImageHight;
}


@end
